<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function doDelay(time) {
            return new Promise((resolve, reject) => {
                console.log("启动异步任务");
                setTimeout(() => {
                    console.log("异步任务开始执行...");
                    const time = Date.now();
                    if (time % 2 === 1) {
                        resolve("成功的数据" + time)
                    } else {
                        reject("失败的数据" + time)
                    }

                }, time);
            })

        }
        const p = doDelay(5000);
        p
        .then(value => console.log(value))
        .catch(value => console.log(value));

        console.log();
    </script>
</body>

</html>